package se.sweco.gpsservice.datatypes;

public class GPSDataGPVTG {
	float track = 0.0f;
	float magneticTrack = 0.0f;
	float groundSpeedKnot = 0.0f;
	float groundSpeedKilometers = 0.0f;
	
	public void parseData(String data) {
		String[] gpsData = data.split(",");
		String gpsDataType = gpsData[0].substring(1);
		
		if(gpsDataType.equals("GPVTG")) {
			for(int i = 1; i < gpsData.length - 1; i+=2) {
				if(gpsData[i+1].equals("T")){
					if(!gpsData[i].trim().equals("")) 
						track = new Float(gpsData[i]).floatValue();
				} else if(gpsData[i+1].equals("M")){
					if(!gpsData[i].trim().equals("")) 
						magneticTrack = new Float(gpsData[i]).floatValue();
				} else if(gpsData[i+1].equals("N")){
					if(!gpsData[i].trim().equals("")) 
						groundSpeedKnot = new Float(gpsData[i]).floatValue();
				} else if(gpsData[i+1].equals("K")){
					if(!gpsData[i].trim().equals("")) 
						groundSpeedKilometers = new Float(gpsData[i]).floatValue();
				}
			}
		}
	}
	
	public String toString() {
		StringBuffer sb = new StringBuffer();
		sb.append("Track: " + this.track + "\n");
		sb.append("MagneticTrack: " + this.magneticTrack + "\n");
		sb.append("SpeedKnots: " + this.groundSpeedKnot + "\n");
		sb.append("SpeedKilometers: " + this.groundSpeedKilometers + "\n");
		return sb.toString();
	}

	public float getTrack() {
		return track;
	}

	public void setTrack(float track) {
		this.track = track;
	}

	public float getMagneticTrack() {
		return magneticTrack;
	}

	public void setMagneticTrack(float magneticTrack) {
		this.magneticTrack = magneticTrack;
	}

	public float getGroundSpeedKnot() {
		return groundSpeedKnot;
	}

	public void setGroundSpeedKnot(float groundSpeedKnot) {
		this.groundSpeedKnot = groundSpeedKnot;
	}

	public float getGroundSpeedKilometers() {
		return groundSpeedKilometers;
	}

	public void setGroundSpeedKilometers(float groundSpeedKilometers) {
		this.groundSpeedKilometers = groundSpeedKilometers;
	}
	
}
